package com.jy.wms.service;

import com.jy.wms.common.UUIDUtils;
import com.jy.wms.common.annotions.BaseServiceDescribe;
import com.jy.wms.common.base.BaseService;
import com.jy.wms.common.base.ServiceException;
import com.jy.wms.common.base.SucessException;
import com.jy.wms.pojo.WmsAsnEnclosure;
import com.jy.wms.pojo.WmsPoEnclosure;
import com.jy.wms.dao.WmsPoEnclosureMapper;
import org.springframework.stereotype.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

    /**
    * @ClassName: WmsPoEnclosureService.java
    * @Description: TODO(这里用一句话描述这个类的作用)
    * @Author LH
    * @Date Tue Dec 19 10:23:43 GMT+08:00 2017
    */

    @Service
    public class WmsPoEnclosureService extends BaseService<WmsPoEnclosureMapper,WmsPoEnclosure> {

        /**
         * 根据poid 查询对应的附件列表（不分页）
         * @param poid
         * @return
         */
        @BaseServiceDescribe(moduleName = "采购订单附件管理",btnName = "查询采购订单附件列表")
        public List<WmsPoEnclosure> getListByPoid(String poid)throws ServiceException {
            try {
                return dao.getListByPoid(poid);
            } catch (Exception e) {
                throw new ServiceException("查询采购订单附件列表",e);
            }
        }

        /**
         * 插入一条记录（匹配有值的字段）
         * @param entity 实体对象
         * @return int
         */
        @BaseServiceDescribe(moduleName = "采购订单附件管理",btnName = "新增采购订单附件")
        public void baseInsertSelective( WmsPoEnclosure entity)throws ServiceException,SucessException {
            entity.setId(UUIDUtils.uuid());
            Integer count = dao.baseInsertSelective( entity);
            if(count > 0){
                throw new SucessException("新增采购订单附件");
            }else{
                throw new ServiceException("新增采购订单附件失败，未存入数据库");
            }
        }

        /**
         *修改 （匹配有值的字段）
         * @param entity 主键ID列表
         * @return int
         */
        @BaseServiceDescribe(moduleName = "采购订单附件管理",btnName = "修改采购订单附件")
        public void baseUpdateByPrimaryKeySelective( WmsPoEnclosure entity)throws SucessException,ServiceException{
            Integer count = dao.baseUpdateByPrimaryKeySelective( entity);
            if(count>0){
                throw new SucessException("修改采购订单附件成功");
            }else{
                throw new ServiceException("修改采购订单附件失败，为存入数据库");
            }
        }

        /**
         * 删除（根据ID 批量删除）
         * @param idList 主键ID列表
         * @return int
         */
        @BaseServiceDescribe(moduleName = "采购订单附件管理",btnName = "批量删除采购订单附件")
        @Transactional
        public void baseDeleteBathPrimaryKeys( List<String> idList)throws ServiceException,SucessException{
            Integer count = dao.baseDeleteBathPrimaryKeys( idList );
            if(count == idList.size()){
                throw new SucessException("删除采购订单附件成功");
            }else{
                throw new ServiceException("删除采购订单附件失败,未完全删除");
            }
        }


    }
